package net.oktaeder.office.utils.ordertransformer;

import java.util.ArrayList;
import java.util.Hashtable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.oktaeder.office.model.WorkOrder;
import net.oktaeder.office.model.WorkOrderData.OrderType;
import net.oktaeder.office.view.Mail;

public class SystemMailTransformer implements IMailTransformer {

	private static Log log = LogFactory.getLog(SystemMailTransformer.class);
	
	public Hashtable<String, ArrayList<WorkOrder>> TransformMail(Mail mail) {

		WorkOrder tempOrder;
		Hashtable<String, ArrayList<WorkOrder>> orders;
		ArrayList<WorkOrder> workOrders;
		
		orders = new Hashtable<String, ArrayList<WorkOrder>>();
		workOrders = new ArrayList<WorkOrder>();
			
		if (mail.getMessage().contains("quit")) {
			tempOrder = new WorkOrder();
			tempOrder.setOrderType(OrderType.SystemOrder);
			tempOrder.addValue("action", "quit");
			// log.info("Quit message received, signaling shutdown");
			// MainApplication.getInstance().signalShutDown();	
			workOrders.add(tempOrder);
		}

		orders.put("system", workOrders);
		
		//TODO: implement rest
		log.warn("special case handling not implemented");
		return orders;
	}

}
